package cn.yh.register.msm.receiver;

import cn.yh.register.common.constant.MqConst;
import cn.yh.register.msm.service.MsmService;
import cn.yh.register.vo.msm.MsmVo;
import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MsmReceiver {

    @Autowired
    MsmService msmService;
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(MqConst.EXCHANGE_DIRECT_MSM),
            value = @Queue(name = MqConst.QUEUE_MSM_ITEM, durable = "true"),
            key = MqConst.ROUTING_MSM_ITEM)
    )
    public void receive(Message message, Channel channel, MsmVo msmVo) {
        log.info("【短信服务-接收通知消息】：{}", JSONObject.toJSONString(msmVo));
        //发送短信通知
        msmService.send(msmVo);
    }

}
